package com.biodiv.client.config;

import io.netty.util.concurrent.DefaultThreadFactory;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @Author: tianquan
 * @date: 2024-11-03  20:01
 * @Description: 自定义线程池
 */
public class ThreadPoolConfig {

    private static final int CORE_POOL_SIZE = 3;

    private static final int MAXIMUM_POOL_SIZE = 10;

    private static final long KEEP_ALIVE_TIME = 60;

    private static final TimeUnit UNIT = TimeUnit.SECONDS;

    private static final ArrayBlockingQueue<Runnable> WORK_QUEUE = new ArrayBlockingQueue<>(100);

    private static final ThreadFactory THREAD_FACTORY = new DefaultThreadFactory("my-thread-pool");

    private static final ThreadPoolExecutor.AbortPolicy REJECTED_EXECUTION_HANDLER = new ThreadPoolExecutor.AbortPolicy();

    public static ThreadPoolExecutor THREAD_POOL =
            new ThreadPoolExecutor(CORE_POOL_SIZE, MAXIMUM_POOL_SIZE, KEEP_ALIVE_TIME, UNIT,
                    WORK_QUEUE, THREAD_FACTORY, REJECTED_EXECUTION_HANDLER);

}
